/**
 * 
 */
package se.chalmers.spexet.booking.model;

import se.chalmers.spexet.booking.common.InvalidOrderModificationException;

/**
 * @author Winquman
 *
 */
public class Ticket {
	private final int ticketID;
	private int ticketType;
	private Order order;
	private boolean finalized;
	
	public static final int CHALMERIST = 1;
	public static final int STUDENT = 2;
	public static final int VUXEN = 3;
	public static final int KALAS_CHALMERIST = 11;
	public static final int KALAS_STUDENT = 12;
	public static final int KALAS_VUXEN = 13;
	
	public Ticket(int ticketID) {

		order = null;
		this.ticketID = ticketID;
		finalized = false;
	}
	
	// Returns cost of ticket
	public int order(Order order, int ticketType) throws InvalidOrderModificationException {
		if(order != null)
			throw new InvalidOrderModificationException("Ticket is already assigned to order " + this.order +
					", but order " + order + " attempted an order().");
		this.order = order;
		this.ticketType = ticketType;
		
		return ModelSettings.getPrice(ticketType);
	}
	
	public void cancelOrder(Order order) throws InvalidOrderModificationException {
		if(this.order.equals(order))
			this.order = null;
		else
			throw new InvalidOrderModificationException("Ticket is currently assigned to order " + this.order +
					", but order " + order + " tried to cancel assignment.");
	}
	
	public boolean isFree() {
		if(order == null)
			return true;
		else
			return false;
	}
	
	public void finalize(Order order) throws InvalidOrderModificationException {
		if(this.order.equals(order))
			finalized = true;
		else
			throw new InvalidOrderModificationException("Ticket is assigned to order " + this.order + 
					", but order " + order + "tried to finalize.");
		
	}
	
	public int getTicketType() {
		return this.ticketType;
	}
}
